import GCJ_CLASS_TYPE = require('./../../common/GCJ_CLASS_TYPE');
import Serializer = require('./../base/Serializer');
var CONFIG=require('../../../../common/config');
export  = SJGXY;

/**
 *
 * @author 
 *
 */
class SJGXY extends Serializer{
    public x: Array<string>=new Array<string>(); 
    public y: Array<string>=new Array<string>();
    
    public constructor(g?) {
        super(g);
        
        this.ct = GCJ_CLASS_TYPE.CLASS_TYPE_SJGXY;
    }
    // 根据数据创建
    public static from(xs:Array<string>, ys:Array<string>, g?):SJGXY{
        var ret: SJGXY=new SJGXY(g);
        ret.x=xs;
        ret.y=ys;
        return ret;
    }
    
    // 从json对象(注意不是json字符串)中解析
    public fromJson(jsonObj, versionId) {
        super.fromJson(jsonObj, versionId);
        
        this.x.splice(0, this.x.length);
        if (jsonObj.hasOwnProperty('x')) {
            this.x = jsonObj.x;
        }
        
        this.y.splice(0, this.y.length);
        if (jsonObj.hasOwnProperty('y')) {
            this.y = jsonObj.y;
        }
    }
    
    // 转成json字符串
    public toJson(): string {
        // 去掉父json字符串的头尾
        var superJson = super.toJson();
        superJson = superJson.substr(1,superJson.length - 2);
        
        var ret = '{';
        ret += superJson;
        ret += ','; 
         
        var arr = '[';
        if (this.x.length > 0) {
            for (var i = 0; i < this.x.length; i++) {
                arr += '"' + this.x[i] + '"';
                arr += ','
            }
            arr = arr.substr(0, arr.length - 1);// 去除多余的逗号
        }
        arr += ']';
        ret += ('"x":' + arr);
        
        ret += ',';
        
        arr = '[';
        if (this.y.length > 0) {
            for (var i = 0; i < this.y.length; i++) {
                arr += '"' + this.y[i] + '"';
                arr += ','
            }
            arr = arr.substr(0, arr.length - 1);// 去除多余的逗号
        }
        arr += ']';
        ret += ('"y":' + arr);
        
        ret += '}';
        return ret;
    }
    
    public copy():SJGXY{
        var ret: SJGXY=new SJGXY();
        ret.fromJson(JSON.parse(this.toJson()),0);
        
        
        return ret;
    }
    
    //SJG_MARK_APPEND--------------------
    public isContentEmpty():boolean {
        if(this.x.length<1 || this.y.length<1 )
        return true;

        var len = this.x.length;
        for (var i = 0; i < len; i++) {
            var item =  this.x[i] ;
            if(item && item.trim().length>0){
                return false;
            }
        }

        len = this.y.length;
        for (var i = 0; i < len; i++) {
            var item =  this.y[i] ;
            if(item && item.trim().length>0){
                return false;
            }
        }

        return true;
    }

    
}//SJG_MARK_END-------------------------
